package br.com.social.mobile.dao;

import java.util.List;

import javax.persistence.Query;

import org.apache.log4j.Logger;

import br.com.social.mobile.entities.User;


public class UserDAO extends GenericDAO<User>{
	
	private Logger logger = Logger.getLogger(UserDAO.class);
	
		@SuppressWarnings("unchecked")
		public List<User> getListByIdProfile(Long nuIdProfile) {
			try {
				createEntityManager();
				Query query = entityManager
						.createQuery("select p FROM User p where p.nuIdProfile= :nuIdProfile order by p.id");
				query.setParameter("nuIdProfile", nuIdProfile);

				return query.getResultList();
			} catch (Exception e) {
				logger.error(e);
				return null;
			}
			
		}	
		
		@SuppressWarnings("unchecked")
		public List<User> getListUsersGpsPosition(Integer nuRaiusGps) {
			try {
				createEntityManager();
				Query query = entityManager
						.createQuery("select p FROM User p where p.isShowMyPosition = :isShowMyPosition and p.nuLatitude is not null");
				
				query.setParameter("isShowMyPosition", "S");
				
				List<User> usr = query.getResultList();
				return usr;
			} catch (Exception e) {
				logger.error(e);
				return null;
			}
			
		}			
		
 
}
